package com.hl.card.modular.packBack.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.hl.card.common.controller.BaseController;
import com.hl.card.common.persistence.dao.UserMapper;
import com.hl.card.common.persistence.model.DisMemberApply;
import com.hl.card.common.persistence.model.DisMemberInfo;
import com.hl.card.common.persistence.model.User;
import com.hl.card.common.util.DateUtils;
import com.hl.card.common.util.ShortMessageUtil;
import com.hl.card.common.util.StockService;
import com.hl.card.core.log.LogObjectHolder;
import com.hl.card.core.shiro.ShiroKit;
import com.hl.card.core.shiro.ShiroUser;
import com.hl.card.core.support.BeanKit;
import com.hl.card.modular.pack.dao.DisMemberInfoMapper;
import com.hl.card.modular.pack.dao.DisMemberProcessMapper;
import com.hl.card.modular.pack.model.DisMemberApplyModel;
import com.hl.card.modular.pack.model.DisMemberInfoModel;
import com.hl.card.modular.pack.model.DisMemberProcessModel;
import com.hl.card.modular.pack.service.DisMemberApplyService;
import com.hl.card.modular.pack.service.RewardByCount;
import com.hl.card.modular.packBack.service.IProfitScaleService;
import com.hl.card.modular.packBack.service.ISalesDivisionService;
import com.hl.card.modular.packBack.service.PartnerApplyService;
import com.hl.card.mq.Mq4NotifyDemo;
import com.hl.card.mq.MqCustomConfig;

import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import java.net.URLDecoder;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/partnerApply")
public class PartnerApplyController extends BaseController {
	@Resource
	private PartnerApplyService partnerApplyService;

	@Resource
	private DisMemberApplyService disMemberApplyService;
	@Autowired
	private Mq4NotifyDemo mq4NotifyDemo;

	@Resource
	private IProfitScaleService iProfitScaleService;

	@Resource
	private ISalesDivisionService iSalesDivisionService;

	@Autowired
	private ShortMessageUtil shortMessageUtil;

	@Autowired
	private StockService stockService;
	@Resource(name = "disMemberProcessMapper")
	private DisMemberProcessMapper disMemberProcessMapper;

	@Resource(name = "disMemberInfoYMapper")
	private DisMemberInfoMapper disMemberInfoMapper;

	@Resource(name = "userMapper")
	private UserMapper userMapper;

	@Autowired
	private RewardByCount rewardByCount;

	private String PREFIX = "/packback/partnerApply/";
	private String SHOPPREFIX = "/packback/shopApply/";
	private String SINSHOPPREFIX = "/packback/sin_shopApply/";
	private String WHITESHOPPREFIX = "/packback/white_shopApply/";
	private String STARSHOPPREFIX = "/packback/star_shopApply/";
	

	@RequestMapping("")
	public String index() {
		return PREFIX + "partnerApply.html";
	}

	@RequestMapping("/shopIndex")
	public String shop_index() {
		return SHOPPREFIX + "shopApply.html";
	}
	
	@RequestMapping("/sinShopIndex")
	public String sinShopIndex() {
		return SINSHOPPREFIX + "sin_shopApply.html";
	}
	
	@RequestMapping("/whiteShopIndex")
	public String whiteShopIndex() {
		return WHITESHOPPREFIX + "white_shopApply.html";
	}
	
	@RequestMapping("/starShopIndex")
	public String starShopIndex() {
		return STARSHOPPREFIX + "star_shopApply.html";
	}

	/**
	 * 跳转到添加矿机合伙人
	 */
	@RequestMapping(value = "/partnerApply_add")
	public Object partnerApplyAdd() {
		return PREFIX + "partnerApply_add.html";
	}

	/**
	 * 跳转到添加商城合伙人
	 */
	@RequestMapping(value = "/shopApply_add")
	public Object shopApplyAdd() {
		return SHOPPREFIX + "shopApply_add.html";
	}
	
	
	/**
	 * 跳转到添加单品
	 */
	@RequestMapping(value = "/sinShopApply_add")
	public Object sinShopApplyAdd() {
		return SINSHOPPREFIX + "sin_shopApply_add.html";
	}

	/**
	 * 跳转到添加百星
	 */
	@RequestMapping(value = "/whiteShopApply_add")
	public Object whiteShopApplyAdd() {
		return WHITESHOPPREFIX + "white_shopApply_add.html";
	}


	/**
	 * 跳转到添加品牌
	 */
	@RequestMapping(value = "/starShopApply_add")
	public Object starShopApplyAdd() {
		return STARSHOPPREFIX + "star_shopApply_add.html";
	}
	
	
	
	/**
	 * 跳转到跟单
	 */
	@RequestMapping(value = "/partnerApply_follow/{partnerApplyId}")
	public Object partnerApplyFollow(@PathVariable Integer partnerApplyId,
			Model model) {
		DisMemberApply disMemberApply = partnerApplyService
				.selectById(partnerApplyId);
		Map<String, Object> partnerApplyMap = BeanKit.beanToMap(disMemberApply);
		model.addAttribute("partnerApply", partnerApplyMap);
		LogObjectHolder.me().set(disMemberApply);
		return PREFIX + "partnerApply_follow.html";
	}

	/**
	 * 跳转到签约
	 */
	@RequestMapping(value = "/partnerApply_sign/{partnerApplyId}")
	public Object partnerApplySign(@PathVariable Integer partnerApplyId,
			Model model) {
		DisMemberApply disMemberApply = partnerApplyService
				.selectById(partnerApplyId);
		Map<String, Object> partnerApplyMap = BeanKit.beanToMap(disMemberApply);
		model.addAttribute("partnerApply", partnerApplyMap);
		LogObjectHolder.me().set(disMemberApply);
		return PREFIX + "partnerApply_sign.html";
	}

	/**
	 * 跳转到修改
	 */
	@RequestMapping(value = "/partnerApply_update/{partnerApplyId}")
	public Object partnerApplyUpdate(@PathVariable Integer partnerApplyId,
			Model model) {
		DisMemberApply disMemberApply = partnerApplyService
				.selectById(partnerApplyId);
		Map<String, Object> partnerApplyMap = BeanKit.beanToMap(disMemberApply);
		model.addAttribute("partnerApply", partnerApplyMap);
		LogObjectHolder.me().set(disMemberApply);
		return PREFIX + "partnerApply_edit.html";
	}

	/**
	 * 跳转到收件信息
	 */
	@RequestMapping(value = "/partnerApply_exp/{partnerApplyId}")
	public Object partnerApplyExp(@PathVariable Integer partnerApplyId,
			Model model) {
		DisMemberApply disMemberApply = partnerApplyService
				.selectById(partnerApplyId);
		Map<String, Object> partnerApplyMap = BeanKit.beanToMap(disMemberApply);
		model.addAttribute("partnerApply", partnerApplyMap);
		LogObjectHolder.me().set(disMemberApply);
		return PREFIX + "partnerApply_exp.html";
	}

	/**
	 * 获取购买矿机列表
	 */
	@RequestMapping(value = "/list")
	@ResponseBody
	public Object list(String order, Integer offset, Integer limit,
			String disUsername, String bindingPhone, Integer status,
			String applytime, String applytime_end) {
		Map<String, Object> map = new HashMap<>();
		map.put("order", order);
		map.put("offset", offset);
		map.put("limit", limit);
		map.put("dis_user_name", disUsername);
		map.put("bindingPhone", bindingPhone);
		map.put("status", status);
		map.put("applytime", applytime);
		map.put("applytime_end", applytime_end);
		map.put("type", 0);

		List<DisMemberApply> list = partnerApplyService.selectList(map);

		System.out.println(list);
		return list;
	}
	
	/**
	 * 导出
	 */
	@RequestMapping(value = "/excelStarShopList")
	@ResponseBody
	public void excelStarShopList(String applytime, String applytime_end,
			Integer payStatus, String recommendation_no,
			HttpServletResponse response) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("recommendation_no", recommendation_no);
		map.put("applytime", applytime);
		map.put("applytime_end", applytime_end);
		map.put("type", 4);
		map.put("payStatus", payStatus);

		List<DisMemberApply> list = partnerApplyService.selectList(map);
		// 声明一个头部信息
		List<String> headers = Arrays.asList("记录编号", "用户姓名", "绑定手机", "推荐人推荐码",
				"支付金额", "支付方式", "支付渠道", "缴费回执号", "支付时间","收款账号", "状态", "创建时间");
		// 声明一个工作薄
		HSSFWorkbook workbook = new HSSFWorkbook();
		// 生成一个表格
		HSSFSheet sheet = workbook.createSheet();
		sheet.setDefaultColumnWidth((short) 24);
		HSSFCellStyle style = workbook.createCellStyle();
		style.setBorderBottom(BorderStyle.THIN); // 下边框
		style.setBorderLeft(BorderStyle.THIN);// 左边框
		style.setBorderTop(BorderStyle.THIN);// 上边框
		style.setBorderRight(BorderStyle.THIN);// 右边框
		style.setAlignment(HorizontalAlignment.CENTER); // 居中
		style.setFillForegroundColor((short) 13);// 设置背景色
		style.setFillPattern(FillPatternType.SOLID_FOREGROUND);

		HSSFCellStyle style2 = workbook.createCellStyle();
		style2.setBorderBottom(BorderStyle.THIN); // 下边框
		style2.setBorderLeft(BorderStyle.THIN);// 左边框
		style2.setBorderTop(BorderStyle.THIN);// 上边框
		style2.setBorderRight(BorderStyle.THIN);// 右边框
		style2.setAlignment(HorizontalAlignment.CENTER); // 居中
		HSSFRow row = sheet.createRow(0);

		for (String head : headers) {
			HSSFCell cell = row.createCell(headers.indexOf(head));
			HSSFRichTextString richString = new HSSFRichTextString(head);
			HSSFFont font3 = workbook.createFont();
			font3.setBold(true);
			richString.applyFont(font3);
			cell.setCellValue(richString);
			cell.setCellStyle(style);

		}
		for (int i = 0; i < list.size(); i++) {
			row = sheet.createRow(i + 1);
			DisMemberApply disMemberApply= list.get(i);
			int j=0;
			HSSFCell cell = row.createCell(j);
			String textValue = disMemberApply.getOrder_no().toString();
			HSSFRichTextString richString = new HSSFRichTextString(textValue);  //订单编号
			cell.setCellValue(richString);
			cell.setCellStyle(style2);
			j++;
			
			HSSFCell cell2 = row.createCell(j);
			String textValue2 = disMemberApply.getUserName()==null?"":disMemberApply.getUserName();
			HSSFRichTextString richString2 = new HSSFRichTextString(textValue2);   //用户名
			cell2.setCellValue(richString2);
			cell2.setCellStyle(style2);
			j++;
			
			HSSFCell cell3 = row.createCell(j);
			String textValue3 = disMemberApply.getBindingPhone()==null?"":disMemberApply.getBindingPhone();   //绑定手机
			HSSFRichTextString richString3 = new HSSFRichTextString(textValue3);
			cell3.setCellValue(richString3);
			cell3.setCellStyle(style2);
			j++;
			
			
			HSSFCell cell4 = row.createCell(j);
			String textValue4 = disMemberApply.getRecommendationNo()==null?"":disMemberApply.getRecommendationNo();   //推荐人推荐码
			HSSFRichTextString richString4 = new HSSFRichTextString(textValue4);
			cell4.setCellValue(richString4);
			cell4.setCellStyle(style2);
			j++;
			
			HSSFCell cell5 = row.createCell(j);
			String textValue5 = disMemberApply.getPayMoney()==null?"":disMemberApply.getPayMoney()+"";   //支付金额
			HSSFRichTextString richString5 = new HSSFRichTextString(textValue5);
			cell5.setCellValue(richString5);
			cell5.setCellStyle(style2);
			j++;
			
			HSSFCell cell6 = row.createCell(j);
			String textValue6 = disMemberApply.getZhifufangshi()==null?"":disMemberApply.getZhifufangshi()+"";   //支付方式
			HSSFRichTextString richString6 = new HSSFRichTextString(textValue6);
			cell6.setCellValue(richString6);
			cell6.setCellStyle(style2);
			j++;
			
			HSSFCell cell7 = row.createCell(j);
			String textValue7 = disMemberApply.getPayChannel()==null?"":disMemberApply.getPayChannel()+"";   //支付渠道
			HSSFRichTextString richString7 = new HSSFRichTextString(textValue7);
			cell7.setCellValue(richString7);
			cell7.setCellStyle(style2);
			j++;
			
			HSSFCell cell8 = row.createCell(j);
			String textValue8 = disMemberApply.getFlowNo()==null?"":disMemberApply.getFlowNo()+"";   //缴费回执号
			HSSFRichTextString richString8 = new HSSFRichTextString(textValue8);
			cell8.setCellValue(richString8);
			cell8.setCellStyle(style2);
			j++;
			
			HSSFCell cell9 = row.createCell(j);
			String textValue9 = disMemberApply.getPayTime()==null?"":DateUtils.DateToStr(disMemberApply.getPayTime(),"yyyy-MM-dd HH:mm:ss");   //支付时间
			HSSFRichTextString richString9 = new HSSFRichTextString(textValue9);
			cell9.setCellValue(richString9);
			cell9.setCellStyle(style2);
			j++;
			
			
			HSSFCell cell12 = row.createCell(j);
			String textValue12 = disMemberApply.getRec_platform()==null?"":disMemberApply.getRec_platform();   //收款平台
			HSSFRichTextString richString12 = new HSSFRichTextString(textValue12);
			cell12.setCellValue(richString12);
			cell12.setCellStyle(style2);
			j++;
			
			HSSFCell cell10 = row.createCell(j);
			String textValue10 = disMemberApply.getZhuangtai()==null?"":disMemberApply.getZhuangtai()+"";   //状态
			HSSFRichTextString richString10 = new HSSFRichTextString(textValue10);
			cell10.setCellValue(richString10);
			cell10.setCellStyle(style2);
			j++;
			
			HSSFCell cell11 = row.createCell(j);
			String textValue11 = disMemberApply.getApplyTime()==null?"":DateUtils.DateToStr(disMemberApply.getApplyTime(),"yyyy-MM-dd HH:mm:ss");   //创建时间
			HSSFRichTextString richString11 = new HSSFRichTextString(textValue11);
			cell11.setCellValue(richString11);
			cell11.setCellStyle(style2);
		}

		response.setContentType("application/octet-stream");
		try{
		response.setHeader("Content-disposition", "attachment;filename="
				+ new String(("入驻品牌记录.xls").getBytes("UTF-8"), "ISO8859-1"));// 默认Excel名称
		response.flushBuffer();
		workbook.write(response.getOutputStream());
		}catch(Exception ex)
		{
			ex.printStackTrace();
		}
	}
	
	
	/**
	 * 导出
	 */
	@RequestMapping(value = "/excelWhiteShopList")
	@ResponseBody
	public void excelWhiteShopList(String applytime, String applytime_end,
			Integer payStatus, String recommendation_no,
			HttpServletResponse response) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("recommendation_no", recommendation_no);
		map.put("applytime", applytime);
		map.put("applytime_end", applytime_end);
		map.put("type", 3);
		map.put("payStatus", payStatus);

		List<DisMemberApply> list = partnerApplyService.selectList(map);
		// 声明一个头部信息
		List<String> headers = Arrays.asList("记录编号", "用户姓名", "绑定手机", "推荐人推荐码",
				"支付金额", "支付方式", "支付渠道", "缴费回执号", "支付时间","收款账号", "状态", "创建时间");
		// 声明一个工作薄
		HSSFWorkbook workbook = new HSSFWorkbook();
		// 生成一个表格
		HSSFSheet sheet = workbook.createSheet();
		sheet.setDefaultColumnWidth((short) 24);
		HSSFCellStyle style = workbook.createCellStyle();
		style.setBorderBottom(BorderStyle.THIN); // 下边框
		style.setBorderLeft(BorderStyle.THIN);// 左边框
		style.setBorderTop(BorderStyle.THIN);// 上边框
		style.setBorderRight(BorderStyle.THIN);// 右边框
		style.setAlignment(HorizontalAlignment.CENTER); // 居中
		style.setFillForegroundColor((short) 13);// 设置背景色
		style.setFillPattern(FillPatternType.SOLID_FOREGROUND);

		HSSFCellStyle style2 = workbook.createCellStyle();
		style2.setBorderBottom(BorderStyle.THIN); // 下边框
		style2.setBorderLeft(BorderStyle.THIN);// 左边框
		style2.setBorderTop(BorderStyle.THIN);// 上边框
		style2.setBorderRight(BorderStyle.THIN);// 右边框
		style2.setAlignment(HorizontalAlignment.CENTER); // 居中
		HSSFRow row = sheet.createRow(0);

		for (String head : headers) {
			HSSFCell cell = row.createCell(headers.indexOf(head));
			HSSFRichTextString richString = new HSSFRichTextString(head);
			HSSFFont font3 = workbook.createFont();
			font3.setBold(true);
			richString.applyFont(font3);
			cell.setCellValue(richString);
			cell.setCellStyle(style);

		}
		for (int i = 0; i < list.size(); i++) {
			row = sheet.createRow(i + 1);
			DisMemberApply disMemberApply= list.get(i);
			int j=0;
			HSSFCell cell = row.createCell(j);
			String textValue = disMemberApply.getOrder_no().toString();
			HSSFRichTextString richString = new HSSFRichTextString(textValue);  //订单编号
			cell.setCellValue(richString);
			cell.setCellStyle(style2);
			j++;
			
			HSSFCell cell2 = row.createCell(j);
			String textValue2 = disMemberApply.getUserName()==null?"":disMemberApply.getUserName();
			HSSFRichTextString richString2 = new HSSFRichTextString(textValue2);   //用户名
			cell2.setCellValue(richString2);
			cell2.setCellStyle(style2);
			j++;
			
			HSSFCell cell3 = row.createCell(j);
			String textValue3 = disMemberApply.getBindingPhone()==null?"":disMemberApply.getBindingPhone();   //绑定手机
			HSSFRichTextString richString3 = new HSSFRichTextString(textValue3);
			cell3.setCellValue(richString3);
			cell3.setCellStyle(style2);
			j++;
			
			
			HSSFCell cell4 = row.createCell(j);
			String textValue4 = disMemberApply.getRecommendationNo()==null?"":disMemberApply.getRecommendationNo();   //推荐人推荐码
			HSSFRichTextString richString4 = new HSSFRichTextString(textValue4);
			cell4.setCellValue(richString4);
			cell4.setCellStyle(style2);
			j++;
			
			HSSFCell cell5 = row.createCell(j);
			String textValue5 = disMemberApply.getPayMoney()==null?"":disMemberApply.getPayMoney()+"";   //支付金额
			HSSFRichTextString richString5 = new HSSFRichTextString(textValue5);
			cell5.setCellValue(richString5);
			cell5.setCellStyle(style2);
			j++;
			
			HSSFCell cell6 = row.createCell(j);
			String textValue6 = disMemberApply.getZhifufangshi()==null?"":disMemberApply.getZhifufangshi()+"";   //支付方式
			HSSFRichTextString richString6 = new HSSFRichTextString(textValue6);
			cell6.setCellValue(richString6);
			cell6.setCellStyle(style2);
			j++;
			
			HSSFCell cell7 = row.createCell(j);
			String textValue7 = disMemberApply.getPayChannel()==null?"":disMemberApply.getPayChannel()+"";   //支付渠道
			HSSFRichTextString richString7 = new HSSFRichTextString(textValue7);
			cell7.setCellValue(richString7);
			cell7.setCellStyle(style2);
			j++;
			
			HSSFCell cell8 = row.createCell(j);
			String textValue8 = disMemberApply.getFlowNo()==null?"":disMemberApply.getFlowNo()+"";   //缴费回执号
			HSSFRichTextString richString8 = new HSSFRichTextString(textValue8);
			cell8.setCellValue(richString8);
			cell8.setCellStyle(style2);
			j++;
			
			HSSFCell cell9 = row.createCell(j);
			String textValue9 = disMemberApply.getPayTime()==null?"":DateUtils.DateToStr(disMemberApply.getPayTime(),"yyyy-MM-dd HH:mm:ss");   //支付时间
			HSSFRichTextString richString9 = new HSSFRichTextString(textValue9);
			cell9.setCellValue(richString9);
			cell9.setCellStyle(style2);
			j++;
			
			
			HSSFCell cell12 = row.createCell(j);
			String textValue12 = disMemberApply.getRec_platform()==null?"":disMemberApply.getRec_platform();   //收款平台
			HSSFRichTextString richString12 = new HSSFRichTextString(textValue12);
			cell12.setCellValue(richString12);
			cell12.setCellStyle(style2);
			j++;
			
			HSSFCell cell10 = row.createCell(j);
			String textValue10 = disMemberApply.getZhuangtai()==null?"":disMemberApply.getZhuangtai()+"";   //状态
			HSSFRichTextString richString10 = new HSSFRichTextString(textValue10);
			cell10.setCellValue(richString10);
			cell10.setCellStyle(style2);
			j++;
			
			HSSFCell cell11 = row.createCell(j);
			String textValue11 = disMemberApply.getApplyTime()==null?"":DateUtils.DateToStr(disMemberApply.getApplyTime(),"yyyy-MM-dd HH:mm:ss");   //创建时间
			HSSFRichTextString richString11 = new HSSFRichTextString(textValue11);
			cell11.setCellValue(richString11);
			cell11.setCellStyle(style2);
		}

		response.setContentType("application/octet-stream");
		try{
		response.setHeader("Content-disposition", "attachment;filename="
				+ new String(("入驻百星记录.xls").getBytes("UTF-8"), "ISO8859-1"));// 默认Excel名称
		response.flushBuffer();
		workbook.write(response.getOutputStream());
		}catch(Exception ex)
		{
			ex.printStackTrace();
		}
	}
	
	
	/**
	 * 导出
	 */
	@RequestMapping(value = "/excelSinShopList")
	@ResponseBody
	public void excelSinShopList(String applytime, String applytime_end,
			Integer payStatus, String recommendation_no,
			HttpServletResponse response) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("recommendation_no", recommendation_no);
		map.put("applytime", applytime);
		map.put("applytime_end", applytime_end);
		map.put("type", 2);
		map.put("payStatus", payStatus);

		List<DisMemberApply> list = partnerApplyService.selectList(map);
		// 声明一个头部信息
		List<String> headers = Arrays.asList("记录编号", "用户姓名", "绑定手机", "推荐人推荐码",
				"支付金额", "支付方式", "支付渠道", "缴费回执号", "支付时间","收款账号", "状态", "创建时间");
		// 声明一个工作薄
		HSSFWorkbook workbook = new HSSFWorkbook();
		// 生成一个表格
		HSSFSheet sheet = workbook.createSheet();
		sheet.setDefaultColumnWidth((short) 24);
		HSSFCellStyle style = workbook.createCellStyle();
		style.setBorderBottom(BorderStyle.THIN); // 下边框
		style.setBorderLeft(BorderStyle.THIN);// 左边框
		style.setBorderTop(BorderStyle.THIN);// 上边框
		style.setBorderRight(BorderStyle.THIN);// 右边框
		style.setAlignment(HorizontalAlignment.CENTER); // 居中
		style.setFillForegroundColor((short) 13);// 设置背景色
		style.setFillPattern(FillPatternType.SOLID_FOREGROUND);

		HSSFCellStyle style2 = workbook.createCellStyle();
		style2.setBorderBottom(BorderStyle.THIN); // 下边框
		style2.setBorderLeft(BorderStyle.THIN);// 左边框
		style2.setBorderTop(BorderStyle.THIN);// 上边框
		style2.setBorderRight(BorderStyle.THIN);// 右边框
		style2.setAlignment(HorizontalAlignment.CENTER); // 居中
		HSSFRow row = sheet.createRow(0);

		for (String head : headers) {
			HSSFCell cell = row.createCell(headers.indexOf(head));
			HSSFRichTextString richString = new HSSFRichTextString(head);
			HSSFFont font3 = workbook.createFont();
			font3.setBold(true);
			richString.applyFont(font3);
			cell.setCellValue(richString);
			cell.setCellStyle(style);

		}
		for (int i = 0; i < list.size(); i++) {
			row = sheet.createRow(i + 1);
			DisMemberApply disMemberApply= list.get(i);
			int j=0;
			HSSFCell cell = row.createCell(j);
			String textValue = disMemberApply.getOrder_no().toString();
			HSSFRichTextString richString = new HSSFRichTextString(textValue);  //订单编号
			cell.setCellValue(richString);
			cell.setCellStyle(style2);
			j++;
			
			HSSFCell cell2 = row.createCell(j);
			String textValue2 = disMemberApply.getUserName()==null?"":disMemberApply.getUserName();
			HSSFRichTextString richString2 = new HSSFRichTextString(textValue2);   //用户名
			cell2.setCellValue(richString2);
			cell2.setCellStyle(style2);
			j++;
			
			HSSFCell cell3 = row.createCell(j);
			String textValue3 = disMemberApply.getBindingPhone()==null?"":disMemberApply.getBindingPhone();   //绑定手机
			HSSFRichTextString richString3 = new HSSFRichTextString(textValue3);
			cell3.setCellValue(richString3);
			cell3.setCellStyle(style2);
			j++;
			
			
			HSSFCell cell4 = row.createCell(j);
			String textValue4 = disMemberApply.getRecommendationNo()==null?"":disMemberApply.getRecommendationNo();   //推荐人推荐码
			HSSFRichTextString richString4 = new HSSFRichTextString(textValue4);
			cell4.setCellValue(richString4);
			cell4.setCellStyle(style2);
			j++;
			
			HSSFCell cell5 = row.createCell(j);
			String textValue5 = disMemberApply.getPayMoney()==null?"":disMemberApply.getPayMoney()+"";   //支付金额
			HSSFRichTextString richString5 = new HSSFRichTextString(textValue5);
			cell5.setCellValue(richString5);
			cell5.setCellStyle(style2);
			j++;
			
			HSSFCell cell6 = row.createCell(j);
			String textValue6 = disMemberApply.getZhifufangshi()==null?"":disMemberApply.getZhifufangshi()+"";   //支付方式
			HSSFRichTextString richString6 = new HSSFRichTextString(textValue6);
			cell6.setCellValue(richString6);
			cell6.setCellStyle(style2);
			j++;
			
			HSSFCell cell7 = row.createCell(j);
			String textValue7 = disMemberApply.getPayChannel()==null?"":disMemberApply.getPayChannel()+"";   //支付渠道
			HSSFRichTextString richString7 = new HSSFRichTextString(textValue7);
			cell7.setCellValue(richString7);
			cell7.setCellStyle(style2);
			j++;
			
			HSSFCell cell8 = row.createCell(j);
			String textValue8 = disMemberApply.getFlowNo()==null?"":disMemberApply.getFlowNo()+"";   //缴费回执号
			HSSFRichTextString richString8 = new HSSFRichTextString(textValue8);
			cell8.setCellValue(richString8);
			cell8.setCellStyle(style2);
			j++;
			
			HSSFCell cell9 = row.createCell(j);
			String textValue9 = disMemberApply.getPayTime()==null?"":DateUtils.DateToStr(disMemberApply.getPayTime(),"yyyy-MM-dd HH:mm:ss");   //支付时间
			HSSFRichTextString richString9 = new HSSFRichTextString(textValue9);
			cell9.setCellValue(richString9);
			cell9.setCellStyle(style2);
			j++;
			
			
			HSSFCell cell12 = row.createCell(j);
			String textValue12 = disMemberApply.getRec_platform()==null?"":disMemberApply.getRec_platform();   //收款平台
			HSSFRichTextString richString12 = new HSSFRichTextString(textValue12);
			cell12.setCellValue(richString12);
			cell12.setCellStyle(style2);
			j++;
			
			HSSFCell cell10 = row.createCell(j);
			String textValue10 = disMemberApply.getZhuangtai()==null?"":disMemberApply.getZhuangtai()+"";   //状态
			HSSFRichTextString richString10 = new HSSFRichTextString(textValue10);
			cell10.setCellValue(richString10);
			cell10.setCellStyle(style2);
			j++;
			
			HSSFCell cell11 = row.createCell(j);
			String textValue11 = disMemberApply.getApplyTime()==null?"":DateUtils.DateToStr(disMemberApply.getApplyTime(),"yyyy-MM-dd HH:mm:ss");   //创建时间
			HSSFRichTextString richString11 = new HSSFRichTextString(textValue11);
			cell11.setCellValue(richString11);
			cell11.setCellStyle(style2);
		}

		response.setContentType("application/octet-stream");
		try{
		response.setHeader("Content-disposition", "attachment;filename="
				+ new String(("入驻单品记录.xls").getBytes("UTF-8"), "ISO8859-1"));// 默认Excel名称
		response.flushBuffer();
		workbook.write(response.getOutputStream());
		}catch(Exception ex)
		{
			ex.printStackTrace();
		}
	}
	
	/**
	 * 导出
	 */
	@RequestMapping(value = "/excelShopList")
	@ResponseBody
	public void excelShopList(String applytime, String applytime_end,
			Integer payStatus, String recommendation_no,
			HttpServletResponse response) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("recommendation_no", recommendation_no);
		map.put("applytime", applytime);
		map.put("applytime_end", applytime_end);
		map.put("type", 1);
		map.put("payStatus", payStatus);

		List<DisMemberApply> list = partnerApplyService.selectList(map);
		// 声明一个头部信息
		List<String> headers = Arrays.asList("记录编号", "用户姓名", "绑定手机", "推荐人推荐码",
				"支付金额", "支付方式", "支付渠道", "缴费回执号", "支付时间","收款账号", "状态", "创建时间");
		// 声明一个工作薄
		HSSFWorkbook workbook = new HSSFWorkbook();
		// 生成一个表格
		HSSFSheet sheet = workbook.createSheet();
		sheet.setDefaultColumnWidth((short) 24);
		HSSFCellStyle style = workbook.createCellStyle();
		style.setBorderBottom(BorderStyle.THIN); // 下边框
		style.setBorderLeft(BorderStyle.THIN);// 左边框
		style.setBorderTop(BorderStyle.THIN);// 上边框
		style.setBorderRight(BorderStyle.THIN);// 右边框
		style.setAlignment(HorizontalAlignment.CENTER); // 居中
		style.setFillForegroundColor((short) 13);// 设置背景色
		style.setFillPattern(FillPatternType.SOLID_FOREGROUND);

		HSSFCellStyle style2 = workbook.createCellStyle();
		style2.setBorderBottom(BorderStyle.THIN); // 下边框
		style2.setBorderLeft(BorderStyle.THIN);// 左边框
		style2.setBorderTop(BorderStyle.THIN);// 上边框
		style2.setBorderRight(BorderStyle.THIN);// 右边框
		style2.setAlignment(HorizontalAlignment.CENTER); // 居中
		HSSFRow row = sheet.createRow(0);

		for (String head : headers) {
			HSSFCell cell = row.createCell(headers.indexOf(head));
			HSSFRichTextString richString = new HSSFRichTextString(head);
			HSSFFont font3 = workbook.createFont();
			font3.setBold(true);
			richString.applyFont(font3);
			cell.setCellValue(richString);
			cell.setCellStyle(style);

		}
		for (int i = 0; i < list.size(); i++) {
			row = sheet.createRow(i + 1);
			DisMemberApply disMemberApply= list.get(i);
			int j=0;
			HSSFCell cell = row.createCell(j);
			String textValue = disMemberApply.getOrder_no().toString();
			HSSFRichTextString richString = new HSSFRichTextString(textValue);  //订单编号
			cell.setCellValue(richString);
			cell.setCellStyle(style2);
			j++;
			
			HSSFCell cell2 = row.createCell(j);
			String textValue2 = disMemberApply.getUserName()==null?"":disMemberApply.getUserName();
			HSSFRichTextString richString2 = new HSSFRichTextString(textValue2);   //用户名
			cell2.setCellValue(richString2);
			cell2.setCellStyle(style2);
			j++;
			
			HSSFCell cell3 = row.createCell(j);
			String textValue3 = disMemberApply.getBindingPhone()==null?"":disMemberApply.getBindingPhone();   //绑定手机
			HSSFRichTextString richString3 = new HSSFRichTextString(textValue3);
			cell3.setCellValue(richString3);
			cell3.setCellStyle(style2);
			j++;
			
			
			HSSFCell cell4 = row.createCell(j);
			String textValue4 = disMemberApply.getRecommendationNo()==null?"":disMemberApply.getRecommendationNo();   //推荐人推荐码
			HSSFRichTextString richString4 = new HSSFRichTextString(textValue4);
			cell4.setCellValue(richString4);
			cell4.setCellStyle(style2);
			j++;
			
			HSSFCell cell5 = row.createCell(j);
			String textValue5 = disMemberApply.getPayMoney()==null?"":disMemberApply.getPayMoney()+"";   //支付金额
			HSSFRichTextString richString5 = new HSSFRichTextString(textValue5);
			cell5.setCellValue(richString5);
			cell5.setCellStyle(style2);
			j++;
			
			HSSFCell cell6 = row.createCell(j);
			String textValue6 = disMemberApply.getZhifufangshi()==null?"":disMemberApply.getZhifufangshi()+"";   //支付方式
			HSSFRichTextString richString6 = new HSSFRichTextString(textValue6);
			cell6.setCellValue(richString6);
			cell6.setCellStyle(style2);
			j++;
			
			HSSFCell cell7 = row.createCell(j);
			String textValue7 = disMemberApply.getPayChannel()==null?"":disMemberApply.getPayChannel()+"";   //支付渠道
			HSSFRichTextString richString7 = new HSSFRichTextString(textValue7);
			cell7.setCellValue(richString7);
			cell7.setCellStyle(style2);
			j++;
			
			HSSFCell cell8 = row.createCell(j);
			String textValue8 = disMemberApply.getFlowNo()==null?"":disMemberApply.getFlowNo()+"";   //缴费回执号
			HSSFRichTextString richString8 = new HSSFRichTextString(textValue8);
			cell8.setCellValue(richString8);
			cell8.setCellStyle(style2);
			j++;
			
			HSSFCell cell9 = row.createCell(j);
			String textValue9 = disMemberApply.getPayTime()==null?"":DateUtils.DateToStr(disMemberApply.getPayTime(),"yyyy-MM-dd HH:mm:ss");   //支付时间
			HSSFRichTextString richString9 = new HSSFRichTextString(textValue9);
			cell9.setCellValue(richString9);
			cell9.setCellStyle(style2);
			j++;
			
			
			HSSFCell cell12 = row.createCell(j);
			String textValue12 = disMemberApply.getRec_platform()==null?"":disMemberApply.getRec_platform();   //收款平台
			HSSFRichTextString richString12 = new HSSFRichTextString(textValue12);
			cell12.setCellValue(richString12);
			cell12.setCellStyle(style2);
			j++;
			
			HSSFCell cell10 = row.createCell(j);
			String textValue10 = disMemberApply.getZhuangtai()==null?"":disMemberApply.getZhuangtai()+"";   //状态
			HSSFRichTextString richString10 = new HSSFRichTextString(textValue10);
			cell10.setCellValue(richString10);
			cell10.setCellStyle(style2);
			j++;
			
			HSSFCell cell11 = row.createCell(j);
			String textValue11 = disMemberApply.getApplyTime()==null?"":DateUtils.DateToStr(disMemberApply.getApplyTime(),"yyyy-MM-dd HH:mm:ss");   //创建时间
			HSSFRichTextString richString11 = new HSSFRichTextString(textValue11);
			cell11.setCellValue(richString11);
			cell11.setCellStyle(style2);
		}

		response.setContentType("application/octet-stream");
		try{
		response.setHeader("Content-disposition", "attachment;filename="
				+ new String(("入驻商城记录.xls").getBytes("UTF-8"), "ISO8859-1"));// 默认Excel名称
		response.flushBuffer();
		workbook.write(response.getOutputStream());
		}catch(Exception ex)
		{
			ex.printStackTrace();
		}
	}

	/**
	 * 获取入驻商城列表
	 */
	@RequestMapping(value = "/shopList")
	@ResponseBody
	public Object shopList(String order, Integer offset, Integer limit,
			String applytime, String applytime_end, Integer payStatus,
			String recommendation_no) {
		Map<String, Object> map = new HashMap<>();
		map.put("order", order);
		map.put("offset", offset);
		map.put("limit", limit);
		map.put("recommendation_no", recommendation_no);
		map.put("applytime", applytime);
		map.put("applytime_end", applytime_end);
		map.put("type", 1);
		map.put("payStatus", payStatus);

		List<DisMemberApply> list = partnerApplyService.selectList(map);

		System.out.println(list);
		return list;
	}
	
	/**
	 * 获取入驻单品列表
	 */
	@RequestMapping(value = "/sinShopList")
	@ResponseBody
	public Object sinShopList(String order, Integer offset, Integer limit,
			String applytime, String applytime_end, Integer payStatus,
			String recommendation_no) {
		Map<String, Object> map = new HashMap<>();
		map.put("order", order);
		map.put("offset", offset);
		map.put("limit", limit);
		map.put("recommendation_no", recommendation_no);
		map.put("applytime", applytime);
		map.put("applytime_end", applytime_end);
		map.put("type", 2);
		map.put("payStatus", payStatus);

		List<DisMemberApply> list = partnerApplyService.selectList(map);

		System.out.println(list);
		return list;
	}
	
	/**
	 * 获取百星列表
	 */
	@RequestMapping(value = "/whiteShopList")
	@ResponseBody
	public Object whiteShopList(String order, Integer offset, Integer limit,
			String applytime, String applytime_end, Integer payStatus,
			String recommendation_no) {
		Map<String, Object> map = new HashMap<>();
		map.put("order", order);
		map.put("offset", offset);
		map.put("limit", limit);
		map.put("recommendation_no", recommendation_no);
		map.put("applytime", applytime);
		map.put("applytime_end", applytime_end);
		map.put("type", 3);
		map.put("payStatus", payStatus);

		List<DisMemberApply> list = partnerApplyService.selectList(map);

		System.out.println(list);
		return list;
	}
	
	/**
	 * 获取品牌列表
	 */
	@RequestMapping(value = "/starShopList")
	@ResponseBody
	public Object starShopList(String order, Integer offset, Integer limit,
			String applytime, String applytime_end, Integer payStatus,
			String recommendation_no) {
		Map<String, Object> map = new HashMap<>();
		map.put("order", order);
		map.put("offset", offset);
		map.put("limit", limit);
		map.put("recommendation_no", recommendation_no);
		map.put("applytime", applytime);
		map.put("applytime_end", applytime_end);
		map.put("type", 4);
		map.put("payStatus", payStatus);

		List<DisMemberApply> list = partnerApplyService.selectList(map);

		System.out.println(list);
		return list;
	}


	/**
	 * 修改
	 */
	@RequestMapping(value = "/update")
	@ResponseBody
	public Object update(@Valid DisMemberApply disMemberApply) {
		disMemberApply.setPayableAmount(disMemberApply.getRobNum() * 9990);
		partnerApplyService.update(disMemberApply);
		return super.SUCCESS_TIP;
	}

	/**
	 * 添加商铺合伙人
	 * 
	 * @return
	 */
	@RequestMapping(value = "/addShop")
	@ResponseBody
	public Object addShop(DisMemberApplyModel disMemberApply) {
		User user = userMapper.selectByPhone(disMemberApply.getBinding_phone());
		if (user != null) {
			if (disMemberApply.getIsUp() != null) {
				if (disMemberApply.getIsUp().equals(1)) // 如果是矿机主升级为店铺
				{
					DisMemberInfoModel model = disMemberInfoMapper
							.queryDisMemberInfoByPhone(disMemberApply
									.getBinding_phone());
					if (model == null) {
						return super.FailuerTip("您还没有购买过矿机！");
					}
					if (model.getRob_num() == null) {
						return super.FailuerTip("您还没有购买过矿机！");
					}

					int rob_count = model.getRob_num();
					int shop_count = model.getShop_num() == null ? 0 : model
							.getShop_num();
					if (rob_count - shop_count <= 0) {
						return super.FailuerTip("矿机升级店铺次数不够！");
					}
				}
			}
			if(!StringUtils.isEmpty(disMemberApply.getRecommendation_no()))
			{
			int count = userMapper.queryRegCodeCount(disMemberApply
					.getRecommendation_no());
			if (count == 0) {
				return super.FailuerTip("推荐码不正确！");
			} else {
				if (user.getReg_code().equalsIgnoreCase(
						disMemberApply.getRecommendation_no())) // 如果用户填写自己的推荐码
				{
					return super.FailuerTip("推荐码不正确！");
				}
				if(!StringUtils.isEmpty(user.getRefer_reg_code()))  //如果用户有上级
				{
					if (!disMemberApply.getRecommendation_no().equalsIgnoreCase(user.getRefer_reg_code())) // 如果用户填写的不是用户上级推荐码
					{
						return super.FailuerTip("推荐码不正确！");
					}
				}
			}
			}
			disMemberApply.setLogin_account(user.getAccount());
			disMemberApply.setUser_name(user.getName());
			Date date = new Date();
			String orderNo = partnerApplyService.creatOrderNo();
			disMemberApply.setStatus(2);
			disMemberApply.setApply_time(date);
			disMemberApply.setPay_status(2);
			disMemberApply.setOrder_no(orderNo);
			disMemberApply.setExamine_time(date);
			disMemberApply.setUser_id(user.getUserId());
			disMemberApply.setType(1); // 商铺
			disMemberApplyService.addShop(disMemberApply, user);
			Object res = rewardByCount.doBatchReward(user.getUserId(), "RZSC", "0",
					12, disMemberApply.getOrder_no());
			System.out.println(res);
			return super.SUCCESS_TIP;
		} else {
			return super.FailuerTip("没有会员账号无法添加合伙人。请先注册成为普通会员");
		}
	}

	/**
	 * 添加单品入驻
	 * 
	 * @return
	 */
	@RequestMapping(value = "/addSinShop")
	@ResponseBody
	public Object addSinShop(DisMemberApplyModel disMemberApply) {
		User user = userMapper.selectByPhone(disMemberApply.getBinding_phone());
		if (user != null) {
			if(!StringUtils.isEmpty(disMemberApply.getRecommendation_no()))
			{
			int count = userMapper.queryRegCodeCount(disMemberApply
					.getRecommendation_no());
			if (count == 0) {
				return super.FailuerTip("推荐码不正确！");
			} else {
				if (user.getReg_code().equalsIgnoreCase(
						disMemberApply.getRecommendation_no())) // 如果用户填写自己的推荐码
				{
					return super.FailuerTip("推荐码不正确！");
				}
				if(!StringUtils.isEmpty(user.getRefer_reg_code()))  //如果用户有上级
				{
					if (!disMemberApply.getRecommendation_no().equalsIgnoreCase(user.getRefer_reg_code())) // 如果用户填写的不是用户上级推荐码
					{
						return super.FailuerTip("推荐码不正确！");
					}
				}
			}
			}
			disMemberApply.setLogin_account(user.getAccount());
			disMemberApply.setUser_name(user.getName());
			Date date = new Date();
			String orderNo = partnerApplyService.creatOrderNo();
			disMemberApply.setStatus(2);
			disMemberApply.setApply_time(date);
			disMemberApply.setPay_status(2);
			disMemberApply.setOrder_no(orderNo);
			disMemberApply.setExamine_time(date);
			disMemberApply.setUser_id(user.getUserId());
			disMemberApply.setType(2); // 998商铺
			disMemberApplyService.addSinShop(disMemberApply, user);
			
			JSONObject map = new JSONObject();
			map.put("function", "makeAward");
			map.put("parentCode", "SCDPRZJL");
			map.put("userId", user.getUserId());
			map.put("amount", "360");
			map.put("orderId", disMemberApply.getOrder_no());
			map.put("queueName", MqCustomConfig.QUEUE_AWARD_ADMIN);
			mq4NotifyDemo.send(MqCustomConfig.QUEUE_AWARD,map.toJSONString());
			return super.SUCCESS_TIP;
		} else {
			return super.FailuerTip("没有会员账号无法添加合伙人。请先注册成为普通会员");
		}
	}
	
	
	/**
	 * 添加百星入驻
	 * 
	 * @return
	 */
	@RequestMapping(value = "/addWhiteShop")
	@ResponseBody
	public Object addWhiteShop(DisMemberApplyModel disMemberApply) {
		User user = userMapper.selectByPhone(disMemberApply.getBinding_phone());
		if (user != null) {
			if(!StringUtils.isEmpty(disMemberApply.getRecommendation_no()))
			{
			int count = userMapper.queryRegCodeCount(disMemberApply
					.getRecommendation_no());
			if (count == 0) {
				return super.FailuerTip("推荐码不正确！");
			} else {
				if (user.getReg_code().equalsIgnoreCase(
						disMemberApply.getRecommendation_no())) // 如果用户填写自己的推荐码
				{
					return super.FailuerTip("推荐码不正确！");
				}
				if(!StringUtils.isEmpty(user.getRefer_reg_code()))  //如果用户有上级
				{
					if (!disMemberApply.getRecommendation_no().equalsIgnoreCase(user.getRefer_reg_code())) // 如果用户填写的不是用户上级推荐码
					{
						return super.FailuerTip("推荐码不正确！");
					}
				}
			}
			}
			disMemberApply.setLogin_account(user.getAccount());
			disMemberApply.setUser_name(user.getName());
			Date date = new Date();
			String orderNo = partnerApplyService.creatOrderNo();
			disMemberApply.setStatus(2);
			disMemberApply.setApply_time(date);
			disMemberApply.setPay_status(2);
			disMemberApply.setOrder_no(orderNo);
			disMemberApply.setExamine_time(date);
			disMemberApply.setUser_id(user.getUserId());
			disMemberApply.setType(3); 
			disMemberApplyService.addWhiteShop(disMemberApply, user);
			
			JSONObject map = new JSONObject();
			map.put("function", "makeAward");
			map.put("parentCode", "BXJHJL");
			map.put("userId", user.getUserId());
			map.put("amount", "360");
			map.put("orderId", disMemberApply.getOrder_no());
			map.put("queueName", MqCustomConfig.QUEUE_AWARD_ADMIN);
			mq4NotifyDemo.send(MqCustomConfig.QUEUE_AWARD,map.toJSONString());
			return super.SUCCESS_TIP;
		} else {
			return super.FailuerTip("没有会员账号无法添加合伙人。请先注册成为普通会员");
		}
	}
	
	
	/**
	 * 添加品牌入驻
	 * 
	 * @return
	 */
	@RequestMapping(value = "/addStarShop")
	@ResponseBody
	public Object addStarShop(DisMemberApplyModel disMemberApply) {
		User user = userMapper.selectByPhone(disMemberApply.getBinding_phone());
		if (user != null) {
			if(!StringUtils.isEmpty(disMemberApply.getRecommendation_no()))
			{
			int count = userMapper.queryRegCodeCount(disMemberApply
					.getRecommendation_no());
			if (count == 0) {
				return super.FailuerTip("推荐码不正确！");
			} else {
				if (user.getReg_code().equalsIgnoreCase(
						disMemberApply.getRecommendation_no())) // 如果用户填写自己的推荐码
				{
					return super.FailuerTip("推荐码不正确！");
				}
				if(!StringUtils.isEmpty(user.getRefer_reg_code()))  //如果用户有上级
				{
					if (!disMemberApply.getRecommendation_no().equalsIgnoreCase(user.getRefer_reg_code())) // 如果用户填写的不是用户上级推荐码
					{
						return super.FailuerTip("推荐码不正确！");
					}
				}
			}
			}
			disMemberApply.setLogin_account(user.getAccount());
			disMemberApply.setUser_name(user.getName());
			Date date = new Date();
			String orderNo = partnerApplyService.creatOrderNo();
			disMemberApply.setStatus(2);
			disMemberApply.setApply_time(date);
			disMemberApply.setPay_status(2);
			disMemberApply.setOrder_no(orderNo);
			disMemberApply.setExamine_time(date);
			disMemberApply.setUser_id(user.getUserId());
			disMemberApply.setType(4); 
			disMemberApplyService.addStarShop(disMemberApply, user);
			
			JSONObject map = new JSONObject();
			map.put("function", "makeAward");
			map.put("parentCode", "PPRZJL");
			map.put("userId", user.getUserId());
			map.put("amount", "360");
			map.put("orderId", disMemberApply.getOrder_no());
			map.put("queueName", MqCustomConfig.QUEUE_AWARD_ADMIN);
			mq4NotifyDemo.send(MqCustomConfig.QUEUE_AWARD,map.toJSONString());
			return super.SUCCESS_TIP;
		} else {
			return super.FailuerTip("没有会员账号无法添加合伙人。请先注册成为普通会员");
		}
	}
	
	
	
	/**
	 * 添加
	 */
	@RequestMapping(value = "/add")
	@ResponseBody
	public Object add(DisMemberApply disMemberApply) {
		User user = userMapper.selectByPhone(disMemberApply.getBindingPhone());
		if (user != null) {
			if (!StringUtils.isEmpty(disMemberApply.getRecommendationNo())) {
				int count = userMapper.queryRegCodeCount(disMemberApply
						.getRecommendationNo());
				if (count == 0) {
					return super.FailuerTip("推荐码不正确！");
				} else {
					if (user.getReg_code().equalsIgnoreCase(
							disMemberApply.getRecommendationNo())) // 如果用户填写自己的推荐码
					{
						return super.FailuerTip("推荐码不正确！");
					}
					if(!StringUtils.isEmpty(user.getRefer_reg_code()))  //如果用户有上级
					{
						if (!disMemberApply.getRecommendationNo().equalsIgnoreCase(user.getRefer_reg_code())) // 如果用户填写的不是用户上级推荐码
						{
							return super.FailuerTip("推荐码不正确！");
						}
					}
				}
			}

			Integer stock = stockService.getStock("redis_key:stock:rob");
			if (disMemberApply.getRobNum() < stock) {
				DisMemberInfoModel disMemberInfoModel = disMemberInfoMapper
						.queryDisMemberInfoByPhone(disMemberApply
								.getBindingPhone());

				String paychanel = disMemberApply.getPayChannel();
				try {
					paychanel = URLDecoder.decode(paychanel, "UTF-8");
				} catch (Exception e) {
					System.out.println(e);
				}
				disMemberApply.setPayChannel(paychanel);
				Date date = new Date();
				DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				String orderNo = partnerApplyService.creatOrderNo();
				disMemberApply.setStatus(2);
				disMemberApply.setPayType(3);
				disMemberApply.setApplyTime(date);
				disMemberApply.setPayStatus(2);
				disMemberApply.setOrder_no(orderNo);
				disMemberApply
						.setLoginAccount(disMemberApply.getBindingPhone());
				disMemberApply.setExamineTime(date);
				disMemberApply.setUserId(user.getUserId());
				disMemberApply
						.setPayableAmount(disMemberApply.getRobNum() * 9990);
				disMemberApply.setType(0); // 矿机
				// 添加合伙人申请列表
				partnerApplyService.save(disMemberApply);
				if (disMemberInfoModel == null) {
					String dis_recomm_pcode = disMemberApply
							.getRecommendationNo();
					// 添加合伙人列表
					DisMemberInfo disMemberInfo = new DisMemberInfo();
					disMemberInfo.setDisUserName(disMemberApply.getUserName());
					disMemberInfo.setDis_recommendation_no(user.getReg_code());
					disMemberInfo.setStatus(0);
					disMemberInfo.setAddTime(format.format(date));
					disMemberInfo.setIdNo(disMemberApply.getIdNo());
					disMemberInfo.setBinding_phone(disMemberApply
							.getBindingPhone());
					disMemberInfo.setDis_recomm_pcode(dis_recomm_pcode);
					disMemberInfo.setBinding_email(user.getEmail());
					disMemberInfo.setDisUserId(user.getUserId());
					// disMemberInfo.setDis_member_no(disMemberApplyService.creatID());
					disMemberInfo.setRobNum(disMemberApply.getRobNum());
					partnerApplyService.saveDisMeberInfo(disMemberInfo);
					userMapper.updateUserIsRemember(user.getUserId());
					if(StringUtils.isEmpty(user.getRefer_reg_code()))
					{
						Map<String, Object> param2 = new HashMap<String, Object>();
						param2.put("user_id", user.getUserId());
						param2.put("refer_reg_code", dis_recomm_pcode);
						userMapper.updateReferRegCode(param2);
					}
					
				} else {
					int total_num = disMemberInfoModel.getRob_num() == null ? 0
							: disMemberInfoModel.getRob_num();
					total_num += 1;
					disMemberInfoModel.setRob_num(total_num);
					disMemberInfoMapper.updateMemberNum(disMemberInfoModel); // 如果存在合伙人信息
																				// 则增加矿机数量
				}

				Object res = rewardByCount.makeAwardByCount("XZHHR",user.getUserId(),
						"0",disMemberApply.getOrder_no(),disMemberApply.getRobNum());// reward.makeDistProfitSplitByCount(user.getUserId(),
															// "XZHHR", "0",
															// disMemberApply.getRobNum());
				System.out.println(res);
				stockService.stock("redis_key:stock:rob", disMemberApply
						.getRobNum().intValue());
				return super.SUCCESS_TIP;
			} else {
				return super.FailuerTip("库存不足！！");
			}
		} else {
			return super.FailuerTip("没有会员账号无法添加合伙人。请先注册成为普通会员");
		}
	}

	/**
	 * 签约
	 */
	@RequestMapping(value = "/sign")
	@ResponseBody
	public Object sign(DisMemberApply disMemberApply) {
		DisMemberApply disMemberApply1 = partnerApplyService
				.selectById(disMemberApply.getId());
		if (disMemberApply1.getRobNum() < stockService
				.getStock("redis_key:stock:rob")) {
			Date date = new Date();
			DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
			String paychanel = disMemberApply.getPayChannel();
			try {
				paychanel = URLDecoder.decode(paychanel, "UTF-8");
			} catch (Exception e) {
				System.out.println(e);
			}
			disMemberApply.setPayChannel(paychanel);
			disMemberApply.setStatus(2);
			disMemberApply.setExamineTime(date);
			disMemberApply.setPayStatus(2);
			partnerApplyService.update(disMemberApply);

			// 添加合伙人列表
			User user = userMapper.selectByPhone(disMemberApply1
					.getBindingPhone());

			DisMemberInfo disMemberInfo = new DisMemberInfo();
			disMemberInfo.setDisUserName(disMemberApply1.getUserName());
			disMemberInfo.setDis_recommendation_no(user.getReg_code());
			disMemberInfo.setStatus(0);
			disMemberInfo.setAddTime(format.format(date));
			disMemberInfo.setIdNo(disMemberApply1.getIdNo());
			disMemberInfo.setBinding_phone(disMemberApply1.getBindingPhone());
			disMemberInfo.setDis_recomm_pcode(disMemberApply1
					.getRecommendationNo());
			if (user.getEmail() != null) {
				disMemberInfo.setBinding_email(user.getEmail());
			}
			disMemberInfo.setDisUserId(user.getUserId());
			// disMemberInfo.setDis_member_no(disMemberApplyService.creatID());
			disMemberInfo.setRobNum(disMemberApply1.getRobNum());
			partnerApplyService.saveDisMeberInfo(disMemberInfo);
			userMapper.updateUserIsRemember(user.getUserId());
			if(StringUtils.isEmpty(user.getRefer_reg_code()))
			{
				Map<String, Object> param2 = new HashMap<String, Object>();
				param2.put("user_id", user.getUserId());
				param2.put("refer_reg_code", disMemberApply1.getRecommendationNo());
				userMapper.updateReferRegCode(param2);
			}
			// 增送比豆
			Object res = rewardByCount.makeAwardByCount("XZHHR",user.getUserId(),  "0",
					disMemberApply1.getOrder_no(),disMemberApply1.getRobNum());// reward.makeDistProfitSplitByCount(user.getUserId(),
													// "XZHHR", "0",
													// disMemberApply.getRobNum());
			System.out.println(res);

			String code = "SMS_136392718";
			String hotline = "4009917909";
			String template = "{\"hotline\":\"" + hotline + "\"}";
			String phone = disMemberApply1.getBindingPhone();
			try {
				SendSmsResponse sendSmsResponse = shortMessageUtil.sendSms(
						phone, code, template);
			} catch (Exception e) {
				System.out.println(e);
			}
			stockService.stock("redis_key:stock:rob",
					disMemberApply1.getRobNum());
			return super.SUCCESS_TIP;
		} else {
			return super.FailuerTip("库存不足，审核失败");
		}
	}

	/**
	 * 跟单
	 */
	@RequestMapping(value = "/follow")
	@ResponseBody
	public Object follow(DisMemberApply disMemberApply) {
		Date date = new Date();
		ShiroUser shiroUser = ShiroKit.getUser();
		String name = shiroUser.getName();
		disMemberApply.setDocumentaryPeople(name);
		disMemberApply.setDocumentaryTime(date);
		disMemberApply.setStatus(1);
		partnerApplyService.update(disMemberApply);

		DisMemberProcessModel disMemberProcess = new DisMemberProcessModel();
		disMemberProcess.setContent("纸质合同已寄出，等待签约");
		disMemberProcess.setTime(date);
		disMemberProcess.setStatus(3);
		disMemberProcess.setUser_id(disMemberApply.getUserId());
		disMemberProcess.setOrder_no(disMemberApply.getOrder_no());
		disMemberProcessMapper.addDisMemberProcess(disMemberProcess);

		return super.SUCCESS_TIP;
	}

	/**
	 * 导出
	 */
	@RequestMapping(value = "/excelList", method = RequestMethod.POST)
	@ResponseBody
	public Object excelList(HttpServletResponse response, String disUsername,
			String bindingPhone, Integer status, String applytime,
			String applytime_end) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("dis_user_name", disUsername);
		map.put("bindingPhone", bindingPhone);
		map.put("status", status);
		map.put("applytime", applytime);
		map.put("applytime_end", applytime_end);

		Map<String, Object> result = new HashMap<String, Object>();
		try {
			partnerApplyService.excelList(map, response);
			result.put("code", 200);
			result.put("msg", "操作成功");
		} catch (Exception e) {
			result.put("code", 201);
			result.put("msg", "操作成功");
		}
		return result;
	}
}
